<html>
<head>
<title>My Form</title>
	<script type="text/javascript" src="<?php echo  base_url() ?>public/kindeditor/kindeditor-all-min.js"></script>
	<script type="text/javascript" src="<?php echo  base_url() ?>public/kindeditor/lang/zh-CN.js"></script>
	<link rel="stylesheet" type="text/css" href="<?php echo  base_url() ?>public/css/bootstrap-theme.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo  base_url() ?>public/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo  base_url() ?>public/css/style.css">
	<link rel="stylesheet" type="text/css" href="<?php echo  base_url() ?>public/css/basic.css">

	<script type="text/javascript" src="<?php echo  base_url() ?>public/js/jquery.min.js"></script>
	<script type="text/javascript" src="<?php echo  base_url() ?>public/js/jquery.upload.js"></script>
</head>
<body style="background:#eee;">
<?php $this->load->view('admin/header')	?>
	<div class="container">
		<div class="col-md-8 col-md-offset-2">
			<form method="POST" action="" >
				<h1><?php echo $title  ?>文章</h1>
				<div class="panel panel-default">
					<div class="panel-heading">
						<div class="form-group">
							<label><span class="error">*</span>title</label>
							<input type="text" name="title" class="form-control" placeholder="title" value="<?php echo set_value('title',$articles->title); ?>">
						</div>
						<?php echo form_error('title'); ?>
						<div class="form-group">
							<label><span class="error">*</span>catalog_id</label>
							<p> 
								<select name="catalog_id" class="form-control">
								<option value="">请选择分类</option>
								<?php
									foreach($catalogs as $c){
								?>
									<option <?php echo set_select("catalog_id",$c['id'],$c['id']==$articles->catalog_id); ?> value="<?=$c['id']?>"><?php echo $c['name'] ?></option>
								<?php
								}
								?>
								</select>
							</p>
						</div>
						<?php echo form_error('catalog_id'); ?>
						<div class="form-group">
							<label><span class="error">*</span>img</label>
							<div class="row">
								<div class="col-sm-6">							
								<input type="text" id="img" name="img" class="form-control" placeholder="img" value="<?php echo set_value("img",$articles->img); ?>">
								<a href="#" id="upload"  class="col-sm- btn btn-success">立刻上传</a>
								</div>
								<div id="preview" class="col-sm-6"></div>
							</div>
						</div>
						<?php echo form_error('img'); ?>
						<div class="form-group">
							<label>desc</label>
							<input type="text" name="desc" id="desc" class="form-control" placeholder="desc" value="<?php echo set_value("desc",$articles->desc); ?>">
						</div>
						<?php echo form_error('desc'); ?>

						<div class="form-group">
							<label><span class="error">*</span>content</label>
							<input type="text" name="content" id="content" class="form-control" placeholder="content" value="<?php echo set_value("content",$articles->content); ?>">
						</div>
						<?php echo form_error('content'); ?>
						<div class="form-group">
							<label>view</label>
							<input type="text" name="view" class="form-control" placeholder="view" value="<?php echo set_value("view",$articles->view); ?>">
						</div>
						<?php echo form_error('view'); ?>
						<div class="form-group">
							<label>recommend</label>
							<input type="text" name="recommend" class="form-control" placeholder="0 or 1" value="<?php echo set_value("recommend",$articles->recommend); ?>">
						</div>
						<?php echo form_error('recommend'); ?>
						<button type="submit" class="btn btn-success btn-block">Submit</button>
						<a  class="btn btn-success btn-block" href="<?php echo site_url('admin/article/index'); ?>">Reback</a>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
<script>
	KindEditor.create('#content,#desc');
	
	$('#upload').click(function(){//添加点击事件，绑定点击事件。
		$.upload({
	        url: '<?php echo site_url("admin/Util/upload");?>', 
	        fileName: 'file',//对应controller里面的FILE。 
	        dataType: 'text',//这个是input框的文本格式
	        onSend: function() {
	                return true;
	        },
	        onComplate: function(data) {
	        	if(data.indexOf('uploads')>=0){//拿到传过来的图片参数，用indexOf来判断是否包含文件文件夹名称
		        	$("#img").val(data);//把img里面的值选中，
		            $("#preview").html('<img style="height:100px;" src="http://localhost/ciblog/'+data+'"/>');//然后把img的值拿到下面ID为preview的标签里面进行实现。
		        }else{
		        	alert(data);
	        	}
	        }
        });
	})
	
</script>
</html>